package com.bicon.botu.account.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.bicon.botu.account.dto.UserInfoDTO;
import com.bicon.botu.account.service.IUserInfoService;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户个人中心管理
 *
 * @author peizp
 * @date 2018/7/16 0012 下午 2:47
 */
@Slf4j
@RestController
@RequestMapping("/userinfo")
public class UserInfoController extends BaseController {

    @Autowired
    private IUserInfoService userInfoService;


    /**
     * 分页根据条件查询用户列表
     * @param current 当前页
     * @param size    每页记录数
     * @return
     */
    @RequestMapping(value = "/getPage", method = RequestMethod.GET)
    public BaseResult getPage(@RequestParam(value = "current") int current,
                              @RequestParam(value = "size") int size,
                              @RequestParam(value = "name", required = false) String name) {
        Page<UserInfoDTO> page = userInfoService.getPagingResources(name,current, size);
        return sendResult200(page);
    }

    /**
     * 初始化所有用户信息到缓存中
     *
     * @return
     */
    @RequestMapping(value = "/initUserInfo", method = RequestMethod.GET)
    public BaseResult initUserInfo() {
        return sendResult200(userInfoService.initUserInfo());
    }
}
